<!--
 * @Author: hw
 * @Date: 2022-11-14 19:19:49
 * @LastEditors: yaoling 1871883713@qq.com
 * @LastEditTime: 2022-12-15 15:36:46
 * @FilePath: \company-world\src\views\issues\components\IssuesEditor.vue
-->
<template>
  <div class="editor-main">
    <v-md-editor
      mode="edit"
      placeholder="请输入内容"
      v-model="props.issuesData.news_content"
      height="420px"
      @copy-code-success="handleCopyCodeSuccess"
      :disabled-menus="[]"
      @upload-image="handleUploadImage"
    ></v-md-editor>
  </div>
</template>

<script lang="ts" setup>
import { PropType } from 'vue'
import { getToken } from '@/utils/token-cache'
import { Itype } from '@/type/index'
import Request from '@/apis/index'
const props = defineProps({
  issuesData: {
    type: Object as PropType<Itype>,
    required: true,
    default: () => {}
  }
})
/**
 * @desc: 图片上传
 */
const baseUrl = 'http://localhost:3008'
const handleUploadImage = (event: any, insertImage: any, files: any) => {
  return new Promise((reslove, resject) => {
    const data = new FormData()
    for (let i in files) {
      data.append('file', files[i])
    }
    Request.post({
      url: `${baseUrl}/md-editor`,
      data: data
    }).then((res) => {
      if (res && res.data.url) {
        insertImage({
          url: res.data.url,
          desc: res.data.filename,
          width: 'auto',
          height: 'auto'
        })
        reslove(res.data.url.replace('_thumb', ''))
      } else {
        resject('上传失败')
      }
    })
  })
}
/**
 * @desc: 图片复制
 * @param {*} code
 * @return {*}
 */
const handleCopyCodeSuccess = (code: string) => {}
</script>

<style scoped></style>
